package com.cy.pj.sys.controller;

import com.cy.pj.sys.pojo.SysUser;
import com.cy.pj.sys.pojo.SysUserMenu;
import com.cy.pj.sys.service.SysMenuService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**从过此controller处理页面请求*/
@Controller
@RequestMapping("/")
public class PageController {

    @RequestMapping("doLoginUI")
    public String doLoginUI(){
        return "login";
    }


    @GetMapping("doPageUI")
    public String doPageUI(){
        return "common/page";
    }

//    @GetMapping("/log/log_list")
//    public String doLogUI(){
//        return "sys/log_list";
//    }

//    @GetMapping("/menu/menu_list")
//    public String doMenuUI(){
//        return "sys/menu_list";
//    }

    //rest风格url,简化view请求处理,但是rest风格的url优先级比较低
    @GetMapping("{module}/{moduleUI}")
    public String doMouduleUI(@PathVariable  String moduleUI){
        return "sys/"+moduleUI;
    }

    @Autowired
    private SysMenuService sysMenuService;

    @GetMapping("doIndexUI")
    public String doIndexUI(Model model){
        //获取登录用户
        SysUser user=(SysUser)SecurityUtils.getSubject().getPrincipal();
        List<SysUserMenu> userMenus=sysMenuService.findUserMenusByUserId(user.getId());
        String username=user.getUsername();
        model.addAttribute("username",username);
        model.addAttribute("userMenus", userMenus);
        return "starter";
    }
}
